

let uu = document.querySelector('ul')
console.log(uu);

let nav = document.querySelector('.nav')


let id = getQueryString('categoryid')

console.log(id);


let titleid = getQueryString('titleid')
console.log(titleid);
function render(data, el) {
    console.log(data, el);
    data.forEach(item => {
        let li = document.createElement('li')
        let r = 'categoryid=' + id
        let html = `
        <a href="比价3详情.html?${r}&productid=${item.productId}&titleid=${titleid}">
            <div class="Png">
                ${item.productImg}
            </div>
            <div class="All">
                <div class="allTop">
                    <h4>${item.productName}</h4>
                    <div>${item.productPrice}</div>
                </div>
                <div class="allbtm">
                    <span>${item.productQuote}</span>
                    <i>${item.productCom}</i>
                </div>
            </div>
        </a>

        `

        li.innerHTML = html

        el.appendChild(li)
    });

}
function getData(pageid = 1, id) {
    // http://chst.vip:1234/api/getproductlist
    fetch(`http://chst.vip:1234/api/getproductlist?pageid${pageid}&categoryid=` + id)
        .then(body => body.json())
        .then(res => {
            console.log(res);
            let total = Math.ceil(res.totalCount / 10) + 1
            console.log(total);//数据总条数


            uu.setAttribute("total", total)
            console.log(uu);
            render(res.result, uu)
            tiao(titleid)

        })

}
getData(1, id)

let pageid = 1
lazyLoad(function () {
    let qq = uu.getAttribute("total")
    console.log(qq);
    pageid++
    if (pageid > qq) {
        return
    }
    getData(pageid, id)

}, 200)

let tiao = function (titleid) {
   
    console.log(nav);
    fetch('http://chst.vip:1234/api/getcategory?titleid=' + titleid)
        .then(body => body.json())
        .then(res => {
            let data = res.result
            console.log(data);
            console.log(id);
            let i = data.findIndex((value) => value.categoryId == id)

            console.log(i);
            console.log(res.result[i]);

            let html1 = `
            <a href="./../index.html"><span>首页></span></span></a>
            <a href="./比价搜索.html"><span class="yi">全部分页></span></span></a>
            <a href="bjssDetail.html?categoryid=${id}&titleid=${titleid}"><span class="er">${data[i].category} </span></a>
            `

            nav.innerHTML = html1

        })
}
tiao(titleid)




//http://chst.vip:1234/api/getproductlist

// categoryid ： 分类id  ( Number类型)，
//   pageid :  页数id   ( Number类型)









